package com.jiandaoshou.adapter;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import com.jiandaoshou.R;
import com.jiandaoshou.entry.BankInfo;
import com.jiandaoshou.utils.LogUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import joanzapata.android.BaseAdapterHelper;
import joanzapata.android.QuickAdapter;

/**
 * Created by Administrator on 2016/9/29.
 */

public class ChoiceYinHangAdapter extends QuickAdapter<ChoiceYinHangAdapter.ChoiceBank> {

    public ChoiceYinHangAdapter(Context context) {
        super(context, R.layout.item_choiceyinhangka);
    }


    private void setDefault(){
        for (int i = 0; i < data.size(); i++) {
            ChoiceBank bank = data.get(i);
            bank.isSelect = false;
        }
    }

    @Override
    protected void convert(BaseAdapterHelper helper, final ChoiceBank bank) {
        LogUtil.e("bank......."+bank.isSelect);
        helper.setText(R.id.tv_choiceyinhangname, bank.bank.getStrBankName());
        AppCompatCheckBox checkBox = helper.getView(R.id.checkbox_yinhangka);
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setDefault();
                bank.isSelect = !bank.isSelect;
                notifyDataSetChanged();
            }
        });
        checkBox.setChecked(bank.isSelect);
    }

    public void update(ChoiceBank bank,int pos){
        getList().get(pos).isSelect=true;
        notifyDataSetChanged();
    }

    public static class ChoiceBank{
        public BankInfo bank;
        public boolean isSelect = false;
    }

}
